package com.multi.service.impl;

import com.multi.entity.SlaveInfo;
import com.multi.mapper.slave.SlaveInfoDao;
import com.multi.service.SlaveInfoService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 用户(SlaveInfo)表服务实现类
 *
 * @author makejava
 * @since 2024-06-19 14:15:28
 */
@Service("slaveInfoService")
public class SlaveInfoServiceImpl implements SlaveInfoService {
    @Resource
    private SlaveInfoDao slaveInfoDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SlaveInfo queryById(Integer id) {
        return this.slaveInfoDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param slaveInfo 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<SlaveInfo> queryByPage(SlaveInfo slaveInfo, PageRequest pageRequest) {
        long total = this.slaveInfoDao.count(slaveInfo);
        return new PageImpl<>(this.slaveInfoDao.queryAllByLimit(slaveInfo, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param slaveInfo 实例对象
     * @return 实例对象
     */
    @Override
    public SlaveInfo insert(SlaveInfo slaveInfo) {
        this.slaveInfoDao.insert(slaveInfo);
        return slaveInfo;
    }

    /**
     * 修改数据
     *
     * @param slaveInfo 实例对象
     * @return 实例对象
     */
    @Override
    public SlaveInfo update(SlaveInfo slaveInfo) {
        this.slaveInfoDao.update(slaveInfo);
        return this.queryById(slaveInfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.slaveInfoDao.deleteById(id) > 0;
    }
}
